package com.yxq.mdt.app.modules.socialcontact.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.withdraw.bean.WithDrawResultBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author L
 * @time 2019-12-10
 * @describe $
 */
public class LiveModel implements IBaseModel {
    @Override
    public void onDestroy() {

    }

    public void addOrUpdateVideo(String targetUserId, int liveType, String liveId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(LiveAPI.class)
                .addOrUpdateVideo(targetUserId, liveType, liveId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<String>() {
            @Override
            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                callback.onError(e.getMessage());
            }

            @Override
            protected void onSuccess(String baseEntity) throws Exception {
                callback.onSuccess(baseEntity);
            }
        });
    }

    public void addOrUpdateVideo(String targetUserId, String liveId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(LiveAPI.class)
                .addOrUpdateVideo(targetUserId, liveId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<String>() {
            @Override
            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                callback.onError(e.getMessage());
            }

            @Override
            protected void onSuccess(String baseEntity) throws Exception {
                callback.onSuccess(baseEntity);
            }
        });
    }

    public void addOrUpdateVoice(String targetUserId, int liveType, String liveId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(LiveAPI.class)
                .addOrUpdateVoice(targetUserId, liveType, liveId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<String>() {
            @Override
            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                callback.onError(e.getMessage());
            }

            @Override
            protected void onSuccess(String baseEntity) throws Exception {
                callback.onSuccess(baseEntity);
            }
        });
    }

    public void addOrUpdateVoice(String targetUserId, String liveId, ApiModel.CommonCallback<String> callback) {
        RetrofitFactory.getJavaRetrofit().create(LiveAPI.class)
                .addOrUpdateVoice(targetUserId, liveId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<String>() {
            @Override
            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                callback.onError(e.getMessage());
            }

            @Override
            protected void onSuccess(String baseEntity) throws Exception {
                callback.onSuccess(baseEntity);
            }
        });
    }

    public void updateEvaluate(String liveId, String comment, int score, ApiModel.CommonCallback<WithDrawResultBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(LiveAPI.class)
                .updateEvaluate(liveId, comment, score)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<WithDrawResultBean>() {
            @Override
            protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                callback.onError(e.getMessage());
            }

            @Override
            protected void onSuccess(WithDrawResultBean baseEntity) throws Exception {
                callback.onSuccess(baseEntity);
            }
        });
    }
}
